using UnityEngine;
using UnityEngine.UI;

public class TextPerspective : BaseMeshEffect
{
    [Lablel("透视值")]
    public float Offset = 0.05f;

    public override void ModifyMesh(VertexHelper vh)
    {
        if (!IsActive())
            return;

        int count = vh.currentVertCount;

        int curNum;
        int verValue;
        float offset;
        UIVertex vertex = new UIVertex();
        for (int i = 0; i < count; i++)
        {
            curNum = i / 4;
            verValue = i % 4;
            vh.PopulateUIVertex(ref vertex, i);
            if (verValue < 2)
            {
                offset = curNum * Offset;
            }
            else
            {
                offset = -curNum * Offset;
            }
            if (verValue == 1)
            {
                offset += Offset;
            }
            else if (verValue == 2)
            {
                offset -= Offset;
            }
            vertex.position.Set(vertex.position.x, vertex.position.y + offset, vertex.position.z);
            vh.SetUIVertex(vertex, i);
        }
    }
}
